package com.example.demo.service;

import com.example.demo.dao.UserMapper;
import com.example.demo.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: lishuo
 * Date: 2023-09-13
 * Time: 16:26
 */
@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;

    @Transactional
    public int insert(UserInfo userInfo) {
        return userMapper.insert(userInfo);
    }

    @Transactional(propagation = Propagation.NESTED)
    public int insert2(UserInfo userInfo) {
        // 构造异常
        int num = 1/0;
        return userMapper.insert(userInfo);
    }
}











